<template>
  <div class="content">
    <!-- 个人中心-历史答卷 -->
    <div class="year">
      <div class="left">
        <p><img :src="img" alt="" /></p>
        <p>{{ name }}</p>
        <div v-for="(item, index) in myself" :key="index">
          <router-link :to="item.url">
            <p><img :src="item.image" alt="" /></p>
            <p>{{ item.text }}</p>
            <p class="jian"><img :src="item.right" alt="" /></p>
          </router-link>
        </div>
      </div>
      <div class="right">
        <div class="da">
          <p>
            <img src="../../assets/lishi (2).png" alt="" />
            {{ dajuan }}
          </p>
        </div>
        <!-- <table cellspacing="0" cellpadding="0" :data="tableData">
          <tr>
            <td>序号</td>
            <td>考试</td>
            <td>交卷时间</td>
            <td>用时</td>
            <td>操作</td>
          </tr>
          <tr>
            <td>1</td>
            <td>{{timu}}</td>
            <td>{{shij}}</td>
            <td>{{time}}</td>
            <td>
              <router-link to="/Model">
                <button>查看</button>
              </router-link>
              
            </td>
          </tr>
        </table> -->
        <div class="list" v-for="(item, index) in list" :key="index">
          <div class="con" :data="tableData">
            <!-- <p class="grey">{{item.num}}</p> -->
            <p class="grey">{{item.test}}</p>
            <p class="grey">{{item.time}}</p>
            <p class="grey">{{item.user_time}}</p>
            <router-link to="/analysis">
              <button>查看</button>
            </router-link>
          </div>
        </div>
        <!-- <div class="block">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="currentPage3"
            :page-size="100"
            layout="prev, pager, next, jumper"
            :total="1000">
          </el-pagination>
        </div> -->
        <!-- <el-table :data="tableData" height="550" border>
          <el-table-column
            prop="number"
            label="序号"
            width="100%"
            align="center"
          >
          </el-table-column>
          <el-table-column prop="test" label="考试" align="center" width="235%">
          </el-table-column>
          <el-table-column
            prop="time"
            label="交卷时间"
            align="center"
            width="150%"
          >
          </el-table-column>
          <el-table-column
            prop="user_time"
            label="用时"
            align="center"
            width="150%"
          >
          </el-table-column>
          <el-table-column prop="look" label="操作" align="center" width="150%">
          </el-table-column>
          
        </el-table> -->
        <el-col :span="24" class="toolbar pageBar">
          <el-pagination
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            layout=" prev, pager, next,total,jumper"
            :total="total"
            background
          >
          </el-pagination>
        </el-col>
      </div>
    </div>
  </div>
</template>
<script>
import Vue from "vue";
import { Table, TableColumn, Pagination } from "element-ui";
import VueResource from "vue-resource";
Vue.use(Table);
Vue.use(TableColumn);
Vue.use(Pagination);
Vue.use(VueResource);
export default {
  data() {
    return {
      tableData: [],
      currentPage: 1, //当前页
      total: 2, //数据总条数
      pageSize: 10, //每页显示的数据条数
      name: "用户名称",
      img: require("../../assets/tx_2.png"),
      myself: [
        {
          image: require("../../assets/my.png"),
          text: "个人信息",
          right: require("../../assets/you.png"),
          url: "/Message",
        },
        {
          image: require("../../assets/timenow.png"),
          text: "历史答卷",
          right: require("../../assets/you1.png"),
          url: "/Year",
        },
        {
          image: require("../../assets/shou.png"),
          text: "我的收藏",
          right: require("../../assets/you.png"),
          url: "/Favorite",
        },
      ],
      list:[
        {num:'1',test:"Java基础练习",time:'2021-03-05 19:00:00',user_time:'一小时20分钟'},
        {num:'1',test:"Java基础练习",time:'2021-03-05 19:00:00',user_time:'一小时20分钟'},
      ],
      dajuan: "历史答卷",
      timu: "JAVA基础练习",
      shij: "2021-03-05 19:00:00",
      time: "1小时20分钟",
    };
  },
  mounted() {
    // chrome
    document.body.scrollTop = 0;
    // firefox
    document.documentElement.scrollTop = 0;
    // safari
    window.pageYOffset = 0;
  },
  methods: {
    //该方法用来从后台拉取数据，以get方式请求
    //例如：默认每页显示10条数据，当用户点击页码1时，向后端请求第0~9条数据
    getData() {
      var start = (this.currentPage - 1) * this.pageSize; //请求的数据从第start条开始
      var end = this.currentPage * this.pageSize - 1; //到第end条结束
      this.$http.get("/api/v1/get_data/?start=" + start + "&end=" + end).then(
        function (response) {
          this.tableData = response.body.logs;
        }
        // function (err) {
        //   console.log(err);
        // }
      );
    },
    //该方法当用户点击页码改变时触发，val为切换到的页码，页码变化后向后台请求新的数据
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getData();
    },
  },
  //该方法为组件创建前的钩子函数，主要用来初始化表格，当表格被加载出来即向后台先请求前10条数据
  beforeCreate: function () {
    this.$http.get("/api/v1/get_data/?start=0&end=10").then(
      function (response) {
        this.total = response.body.log_total;
        this.tableData = response.body.logs;
      },
      function () {
        // console.log(err);err
      }
    );
  },
};
</script>
<style lang="scss" scoped>
.content {
  width: 100%;
  font-size: 16px;

  p {
    margin: 0;
  }

  .year {
    width: 65%;
    margin: 0 auto;
    // min-width: 1066px;
    margin-top: 2rem;
    justify-content: space-between;
    display: flex;

    .left {
      width: 22%;
      padding: 2rem 2%;
      box-shadow: 0px 5px 20px 0px rgba(116, 116, 116, 0.35);
      border-radius: 10px;
      > p {
        text-align: center;
        color: #666666;
        margin-bottom: 1rem;
      }

      > div {
        width: 100%;
        padding: 1rem 0;
        border-top: 1px solid #d0d0d0;
        color: #666666;

        a {
          justify-content: space-between;
          display: flex;
          text-decoration: none;
          color: #666666;
        }

        .jian {
          width: 10%;

          img {
            width: 100%;
            vertical-align: middle;
          }
        }
      }
      > div:nth-child(4) {
        // background: #0096f6;
        > a {
          color: #0096f6 !important;
        }
      }
    }

    .right {
      width: 70%;
      box-shadow: 0px 5px 20px 0px rgba(116, 116, 116, 0.35);
      border-radius: 10px;

      p {
        margin: 0;
      }

      .da {
        width: 96%;
        padding: 2rem 2%;
        color: #0096f6;
        font-size: 24px;
        border-bottom: 2px solid #d9d9d9;
        padding-bottom: 1rem;
        margin-bottom: 1rem;

        img {
          width: 4%;
          vertical-align: middle;
        }
      }

      /deep/ .el-table {
        width: 90%;
        margin: 0 auto;
      }

      /deep/ .el-pagination {
        text-align: center;
        margin-top: 1rem;
      }

      .list {
        width: 94%;
        margin: 0 auto;
        padding: 0.2rem 0 ;
        border-bottom: 1px solid #C7C7C7;

        .con {
          width: 94%;
          justify-content: space-between;
          display: flex;
          align-items: center;
          padding: 7px 0;
          .grey {
            color: #999999;
          }

          button {
            background: #0096f6;
            color: #fff;
            padding: 8px;
            border: 1px solid #0096f6;
            outline: none;
          }
        }
      }

      table {
        width: 86%;
        margin: 0 auto;
        margin-top: 2rem;
        color: #666666;

        td {
          line-height: 60px;
          text-align: center;
          border: 1px solid #d4d4d4;

          button {
            background: #0096f6;
            color: #fff;
            border: 1px solid #0096f6;
            outline: none;
            padding: 0.2rem 8%;
          }
        }
      }

      .block {
        text-align: center;
        margin-top: 3rem;
      }
    }
  }
}
</style>